const Router = require('koa-router')
const router = Router({ prefix: '/users' })

const { find, findById, create, update, delete: del, login, listFollowing, follow, unfollow, listFollowers,
    checkUserExist, followTopic, unfollowTopic, listHandAccount, likeHandAccount, dislikeHandAccount } = require('../controllers/users')
const { secret } = require('../config');
const { checkTopicExist } = require('../controllers/topics')


const jwt = require('koa-jwt')
const auth = jwt({ secret })

router.get('/', find) // 获取所有用户

router.post('/', create) // 注册

router.get('/:id', findById)

router.patch('/:id', auth, update)

router.delete('/:id', auth, del)

router.post('/login', login) // 登录

router.get('/:id/following', listFollowing)

router.get('/:id/followers', listFollowers)

router.put('/following/:id', auth, checkUserExist, follow)

router.delete('/unfollow/:id', auth, checkUserExist, unfollow)

router.put('/followingTopic/:id', auth, checkTopicExist, followTopic)

router.delete('/unfollowTopic/:id', auth, checkTopicExist, unfollowTopic)

router.put('/likeHandAccount/:id', auth, likeHandAccount)

router.delete('/dislikeHandAccount/:id', auth, dislikeHandAccount)



// 获取用户的所有手帐 
// ! 没有解决安全性 现在私密手帐也可以被随意获取
router.get('/:id/handAccounts', listHandAccount)

// todo 列出某人关注的用户的所有手帐
// router.put('/:id/followingHandAccounts', checkUserExist, listFollowingHandA)

module.exports = router

